package edu.bit.water.controller;

import edu.bit.water.dao.TechProcessDao;
import edu.bit.water.dto.DateUtils;
import edu.bit.water.entity.ManagementIndicator;
import edu.bit.water.entity.TechnicalIndicator;
import edu.bit.water.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.*;

import edu.bit.water.entity.TechProcess;
import edu.bit.water.service.TechProcessService;

/**
 * 这里对应数据库中Meta_assessment_indicator表的controller
 * 对应企业管理指标
 * @Author： Page
 */
@Controller
@RequestMapping("/tech_process")
public class TechProcessController extends BaseController{

    @Autowired
    private TechProcessService TechProcessService = new TechProcessService();

//    @ResponseBody
//    @RequestMapping(value = "/select", method=RequestMethod.GET)
//    public Map<String, Object>selectTechProcess(@RequestParam("companyId") String companyId,
//                                                @RequestParam("moduleName") String moduleName) {
//        Map<String, Object> result = new HashMap<>();
//        List<TechProcess> list = TechProcessService.selectTechProcess(companyId, moduleName);
//        result.put("rows", list);
//        return result;
//    }

    @ResponseBody
    @RequestMapping(value = "/select", method=RequestMethod.GET)
    public Map<String, Object>selectTechProcess(@RequestParam("companyId") String companyId) {
        Map<String, Object> result = new HashMap<>();
        UserEntity user = (UserEntity) session.getAttribute("user");//通过这种方式获取当前登录的用户
        List<TechProcess> list;
        if(userDao.testAdmin(Integer.toString(user.getId())) > 0) {//检测用户是否是超级管理员
            list = TechProcessService.selectAllTechProcess();//超级管理员查看所有企业数据
        }
        else {
            list = TechProcessService.selectTechProcess(companyId);//普通用户查看当前企业的数据
        }
        result.put("rows", list);
        return result;
    }

    @ResponseBody
    @RequestMapping("/insert")
    public Map<String, Object> insertTechProcess(TechProcess TechProcess) {
        TechProcess.changeTime();
        return TechProcessService.insertTechProcess(TechProcess);
    }

    /**
     * 删除metaStandard
     * author Page
     */
    @ResponseBody
    @RequestMapping("/delete")
    public Map<String, Object> deleteTechProcess(@RequestBody List<String>TechProcesss) {
        return TechProcessService.deleteTechProcess(TechProcesss);
    }

    @ResponseBody
    @RequestMapping("/update")
    public Map<String, Object> updateMetaStandard(TechProcess TechProcess) {
        Map<String, Object> result = TechProcessService.updateTechProcess(TechProcess);
        return result;
    }
    @RequestMapping(value = "/getLidByCid", method = RequestMethod.GET)
    @ResponseBody
    private Map<String, Object> getLidByCid(int cid) {
        Map<String, Object> modelMap = new HashMap<>();
        int lid = TechProcessService.getLidByCid(cid);
        modelMap.put("result", lid);
        return modelMap;
    }
}